function AttivaFrame(iFrameID)
{
	if (document.getElementById(iFrameID).contentDocument)
	{  
		//Mozilla
		return document.getElementById(iFrameID).contentDocument;
	}
	else
	{
		//Internet Explorer
		return document.frames[iFrameID].document;
	}
}
function setIFrameContentValue(frameID,value)
{
	var doc = AttivaFrame(frameID);
	doc.open();
	doc.write(value);
	doc.close();
}
function getXMLHTTPRequestObject()
{
	var xmlhttp;
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}
function makeAsyncGETRequest(URL,onSuccess)
{
	var xmlhttp = getXMLHTTPRequestObject();
	xmlhttp.open("GET",URL,true);
	xmlhttp.onreadystatechange=function()
	{
		if((xmlhttp.readyState==4) && (xmlhttp.status==200))
		{
			onSuccess(xmlhttp.responseText);
		}
	};
	xmlhttp.send(null);
	return xmlhttp;
}
function makeAsyncPOSTRequest(URL,onSuccess,queryString)
{
	var xmlhttp = getXMLHTTPRequestObject();
	xmlhttp.open("POST",URL,true);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	xmlhttp.setRequestHeader("Content-length", queryString.length);
	xmlhttp.onreadystatechange=function()
	{
		if((xmlhttp.readyState==4) && (xmlhttp.status==200))
		{
			onSuccess(xmlhttp.responseText);
		}
	};
	xmlhttp.send(queryString);
	return xmlhttp;
}
function isBrowserIE()
{
	var sBrowser = navigator.userAgent;
	if (sBrowser.toLowerCase().indexOf('msie') > -1) return true;
	return false;
}
function sendBack()
{
	history.back();
}
function sendTo(loc)
{
	document.location.href = loc;
}
function AttivaFrameExt(iFrameID)
{
	if (opener.document.getElementById(iFrameID).contentDocument)
	{  
		//Mozilla
		return opener.document.getElementById(iFrameID).contentDocument;
	}
	else
	{
		//Internet Explorer
		return opener.document.frames[iFrameID].document;
	}
}

function change_extension(path,newext)
{
	var l = path.length;
	var pos = -1;
	for(var i = l-1; i > 0; i--)
	{
		if(path.charAt(i) == '.')
		{
			pos = i;
			break;
		}
	}
	if(pos == -1)
		return (path + "." + newext);
	else
		return (path.substr(0,pos+1) + newext);
}
function get_thumbnail(srcPath)
{
	return change_extension(srcPath,"_thumb_.jpg");
}
function is_number(str)
{
	if(str == "")
		return false;
	var dotins = false;
	for(var i = 0; i < str.length; i++)
		if(str.charAt(i) < '0' || str.charAt(i) > '9')
			if(str.charAt(i) == '.' | str.charAt(i) == ',')
			{
				if(dotins)
					return false;
				else
					dotins = true;
			}
			else
				return false;
	return true;
}

String.prototype.setCharAt = function(idx, chr)
{
	if((idx > this.length - 1) || idx < 0)
		return this.toString();
	else
		return this.substr(0, idx) + chr + this.substr(idx + 1);
};

function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}

function encode_quotes(str)
{
	str = str.replace(/%/g,"%20");
	str = str.replace(/"/g,"%22");
	str = str.replace(/'/g,"%21");
	return str;
}

function decode_quotes(str)
{
	str = str.replace(/%22/g,'"');
	str = str.replace(/%21/g,"'");
	str = str.replace(/%20/g,"%");
	return str;
}
function urlEncode( s )
{
	return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
}
function urlDecode( s )
{
	return decodeURIComponent( s.replace( /\+/g, '%20' ).replace( /\%21/g, '!' ).replace( /\%27/g, "'" ).replace( /\%28/g, '(' ).replace( /\%29/g, ')' ).replace( /\%2A/g, '*' ).replace( /\%7E/g, '~' ) );
}
function addEvent(elem, type, eventHandle)
{
	if (elem == null || elem == undefined)
		return;
	if ( elem.addEventListener )
	{
		elem.addEventListener( type, eventHandle, false );
	}
	else if ( elem.attachEvent )
	{
		elem.attachEvent( "on" + type, eventHandle );
	}
}
function removeEvent(elem, type, eventHandle)
{
	if (elem == null || elem == undefined)
		return;
	if ( elem.removeEventListener )
	{
		elem.removeEventListener( type, eventHandle, false );
	}
	else if ( elem.detachEvent )
	{
		elem.detachEvent( "on" + type, eventHandle );
	}
}
function changeMetaValue(propertyToFind,newContent)
{
	metatags = document.getElementsByTagName("meta");
	for(i = 0; i < metatags.length; i++)
	{
		if(metatags[i].getAttribute('property') == propertyToFind)
		{
			metatags[i].setAttribute('content',newContent);
			return true;
		}
	}
	return false;
}